import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

public class Demo6 {

    public static void main(String[] args) throws IOException {

        try(InputStream inputStream = new FileInputStream("./demo")){
            while (true){
                //一次读多个字节，数组的长度，自行定义。
                byte[] data = new byte[1024];
                //读操作，就会尽可能把字节数组给填满。
                //填不满的话，能填几个就是几个。
                //此处的 n 就表示实际读了几个字节。
                int n = inputStream.read(data);

                if (n == -1) {
                    //文件读完
                    break;
                }
                for (int i = 0; i < n; i++) {
                    System.out.printf("%x",data[i]);
                }
            }
        }
    }

    public static void main1(String[] args) throws IOException {
        /*InputStream inputStream = null;
        try{
            inputStream = new FileInputStream("./demo");
        }finally {
            inputStream.close();
        }*/

        try (InputStream inputStream = new FileInputStream("./demo");){

            while (true){
                int data = inputStream.read();
                if (data == -1){
                    //文件读完
                    break;
                }
                System.out.printf("%x\n",data);
            }
        }

    }
}
